<?php 
function check_email_address($email) {
  // First, we check that there's one @ symbol, 
  // and that the lengths are right.
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    // Email invalid because wrong number of characters 
    // in one section or wrong number of @ symbols.
    return false;
  }
  // Split it into sections to make life easier
  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++) {
    if
(!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
↪'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
$local_array[$i])) {
      return false;
    }
  }
  // Check if domain is IP. If not, 
  // it should be valid domain name
  if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
    $domain_array = explode(".", $email_array[1]);
    if (sizeof($domain_array) < 2) {
        return false; // Not enough parts to domain
    }
    for ($i = 0; $i < sizeof($domain_array); $i++) {
      if
(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
↪([A-Za-z0-9]+))$",
$domain_array[$i])) {
        return false;
      }
    }
  }
  return true;
}	

  // Set the <title> for the page
  $title = "VegasVIP4u"; 
 
  // Include the Header
  include "includes/header.php";

// Find out what page to show depending on if p is set via a link being clicked
// If someone clicked home or came from a outside link or vegasvip4u.com then show home page
switch ($_GET['p']) {
    case "nightlife":
      // Night Life Page
      echo '<center><img width=100% height=50% src="images/nightlife.jpg" alt="nightclubs" /></center>';
    break;
    case "gentlemensclubs":
      // Gentlemen's Clubs Page
      echo '<center><img width=100% height=50% src="images/gentlemensclubs.jpg" alt="gentlemensclubs" /></center>';
    break;
    case "poolparties":
      echo '<center><img width=100% height=50% src="images/poolparties.jpg" alt="poolparties" /></center>';
    break;
    case "contact":
      // Contact Page
?>
  <!-- Content -->
	<div id="content">
		<p>
	<center>
		<fieldset class="info_fieldset">
			<legend>Fill me out and hit Send Message</legend>
			<div class="note" id="note"></div>
			<div id="fields">
				<form id="ajax-contact-form" method="post">
					<label>Name</label><INPUT class="textbox" type="text" name="name" value=""><br />
					<label>E-Mail</label><INPUT class="textbox" type="text" name="email" value=""><br />
					<label>Subject</label><INPUT class="textbox" type="text" name="subject" value=""><br />	
					<label>Comment / Question(s)</label><TEXTAREA class="textbox" NAME="message" ROWS="5" COLS="25"></TEXTAREA><br />
					<INPUT class="button" id="submit" type="submit" name="submit" value="Send Message">
				</form>
			</div>
		</fieldset>
	</center>
	<script type="text/javascript">
		$("#ajax-contact-form").submit(function(){
			$("#submit").attr('disabled', 'disabled');
			var str = $(this).serialize();
			$.ajax({
				type: "POST",
				url: "includes/sendmail.php",
				data: str,
				success: function(msg) {
					if (msg == 'OK') {
						result = '<div class="notification_ok">Your message has been sent. I will get back to you as soon as possible.  Thank you!</div>';
						$("#fields").hide();
					} else {
						result = msg;
					}
					$("#note").html(result);
					$("#submit").attr('disabled', 'disabled');
				}
			});
			return false;
		});
	</script>
<?php
	break;
    case "register":
		if(!isset($_POST['email'])) {
			echo "
				<form action=?p=register method=post class=form name=frmPhone>
					<div class=form>
						<h3>Fill out all information below then click Register button below</h3>
						<label>
							<span>Full Name</span>
							<input type=text class=input_text required=require name=name id=name />
						</label>
						<label>
							<span>Phone Number</span>
							<input type=text class=input_text required=require name=txtphone id=txtphone maxlength=13 onclick=javascript:getIt(this) />
						</label>
						<label>
							<span>Email</span>
							<input type=text class=input_text required=require name=email id=email />
						</label>
						<label>
							<span>Repeat Email</span>
							<input type=text class=input_text required=require name=email2 id=email2 />
						</label>
						<label>
						   <span>Password</span>
						   <input type=password class=input_text required=require name=password id=password />
						</label>
						<label>
						   <span>Repeat Password</span>
						   <input type=password class=input_text required=require name=password2 id=password2 />
						</label>
							<input type=submit class=button value=Login />
					</div>
				</form>
				<br><br>
			";			
		} else {
			// Grab emails and passwords to check if they are vaild and match
			$email = $_POST['email'];
			$email2 = $_POST['email2'];
			$password = $_POST['password'];
			$password2 = $_POST['password2'];
			if ($email != $email2) {
				// throw error if the emails are not the same
				echo "Email addresses are not the same <a href=?p=register>BACK</a>";
			} else if ($password != $password2) {
				// throw error if passwords are not the same
				echo "Passwords are not the same <a href=?p=register>BACK</a>";
			} else {
				if (!check_email_address($email)) {
					// throw error if email address is not valid
					echo "Email address is not valid <a href=?p=register>BACK</a>";
				} else {
					// get name and phone number
					$name = $_POST['name'];
					$phonenum = $_POST['txtphone'];
					// Set subject to email
					$subject = "VegasVIP4u - New Member Registered!";
					// Show new members register info
					$message = "
						Name: $name <br>
						Phone Number: $phonenum <br>
						Email: $email <br>
					";
					// To send HTML mail, the Content-type header must be set
					$headers  = 'MIME-Version: 1.0' . "\r\n";
					$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
					// Additional headers
					$headers .= 'To: Aaron Weiler <aaron@aaronweiler.net>' . "\r\n";
					$headers .= 'From: VegasVIP4u <b4uclublv@yahoo.com>' . "\r\n";
					$headers .= 'Bcc: sharpe2434@yahoo.com,b4uclublv@yahoo.com' . "\r\n";
					// try to insert user info in to database
          $name = mysql_real_escape_string($name);
          $phone = mysql_real_escape_string($phone);
          $email = mysql_real_escape_string($email);
          $password = mysql_real_escape_string($password);
					$query = "INSERT INTO members (name, phone, email, password) VALUES ('$name', '$phonenum', '$email', '$password')";
					// if they already have name, phonenum, or email in database
					if (!mysql_query($query)) { echo "ERROR: ".mysql_error()." <a href=?p=register>BACK</a>"; }
					// if they don't have any info already in db, try to send email.
					else {
						// Try to send email
						if (mail("aaron@aaronweiler.net", $subject, $message, $headers)) {
							// if mail gets sent show them members image
							echo "<center><img width=100% height=50% src=images/members.jpg alt=freelasvegasvip></center>";	
						} else {
							// If the mail fails to send email send error
							echo "Failed to send email. Please try again <a href=?p=register>BACK</a>"; 
						}
					}
				}
			}
		}
    break;
    case "members":
		if (isset($_POST['email']) && isset($_POST['password']) && !isset($_SESSION['email'])) {
			$email = mysql_real_escape_string($_POST['email']);
			$password = mysql_real_escape_string($_POST['password']);
			$result = mysql_query("SELECT email,password FROM members") or die (mysql_error());
			while($row = mysql_fetch_array($result)) {
				if ($row['email'] == $email && $row['password'] == $password) { 
					session_register("email",$email);
					echo "<center><img width=100% height=50% src=images/members.jpg alt=free drinks stripclubs></center>";
          include "includes/footer.php";
          exit;
				}
			}
			echo "No email/password combonation found in database. Please try again. <a href=?p=members>BACK</a>";
		} else if (isset($_SESSION['email'])) { 
			echo "<center><img width=100% height=50% src=images/members.jpg alt=free limosines las vegas></center>";
		} else if (!isset($_SESSION['email'])) {
			echo "
				<form action=?p=members method=post class=form>
					<div class=form>
						<h3>Don't have a membership with us yet? <a href=?p=register>Click Here</a></h3>
						<label>
							<span>Email</span>
							<input type=text class=input_text required=require name=email id=email/>
						</label>
						<label>
						   <span>Password</span>
						   <input type=password class=input_text required=require name=password id=password/>
						</label>
							<input type=submit class=button value=Login />
					</div>
				</form>
				<br><br>
			";
		}
    break;
    default:
      // Main Content for Home Page
      echo "
  <!-- Content -->
        <center><img src=images/vegassign.jpg width=40% height=40% alt=vegas vip host service /></center>
        <h1>$title</h1>
		<div>
		<div class=form>
						<h3>Fill out all information below then click the Order button below</h3>
						<label>
							<span>Full Name</span>
							<input type=text class=input_text required=require name=name id=name />
						</label>
						<label>
							<span>Phone Number</span>
							<input type=text class=input_text required=require name=txtphone id=txtphone maxlength=13 onclick=javascript:getIt(this) />
						</label>
						<label>
							<span>Email</span>
							<input type=text class=input_text required=require name=email id=email />
						</label>
						<label>
						   <span>Host</span>
						   <input type=text class=input_text required=require name=host2 id=host2 />
						</label>
						<label>
						   <span>Venue</span>
						   <input type=text class=input_text required=require name=venue2 id=venue2 />
						</label>
						<label>
						   <span>No of Guests</span>
						   <input type=text class=input_text required=require name=guests2 id=guests2 />
						</label>
						<label>
						   <span>No of Females</span>
						   <input type=text class=input_text required=require name=females2 id=females2 />
						</label>
						<label>
						   <span>No of Males</span>
						   <input type=text class=input_text required=require name=males2 id=mails2 />
						</label>
							<input type=submit class=button value=Order />
					</div>
				</form>
			</div>
        <!--<h2>
          24/7 VIP Hosting Services
          <br><br>
          providing&#44;
          <br><br>
          Access To All Nightclubs, Stripclubs, and Pool Parties
          <br><br>
          plus&#44;
          <br><br>
          Exclusive Private Parties
          <br>
          <br>
          <br>
          <center>Call us now for a smokin' Vegas experience!</center>
        </h2>
        <h1><center>(831)251-5624</center></h1>
        <br>-->
		
		
      ";
    break;
}
  // Include the Footer
  include "includes/footer.php"; 
?>